package com.framework.base.aqs;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author chaolong.jin
 * @description
 * @date 2019/08/13 09:28
 */
public class StateTest {
    private Lock lock;

    public StateTest(Lock lock) {
        this.lock = lock;
    }

    public static void main(String[] args) {
        Lock lock = new ReentrantLock();
        StateTest stateTest = new StateTest(lock);
        stateTest.testLock();
        stateTest.testLock();
    }
    public void testLock(){
        try {
            this.lock.lock();
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }finally {
            lock.unlock();
        }
    }
}
